package 处理线程安全问题;

/**
 * @作者:侯国威
 * @时间: 2020/4/11/21:50
 * @邮箱:1045077189@qq.com 银行有一账户：
 * 有两个存储户反别想同一个账户村3000，每次存1000，存三次。每次打印存完打印战虎月
 */
public class Account_Test {
    public static void main(String[] args) {
        USER user = new USER();

        Thread t1 = new Thread(user);
        Thread t2 = new Thread(user);
        t1.setName("甲");
        t2.setName("乙");
        t1.start();
        t2.start();

    }
}

class USER implements Runnable {
    private static int money = 1000;
    private static int withdrop = 0;
    Object object = new Object();

    @Override
    public void run() {
        synchronized (object) {
            for (int i = 0; i < 3; i++) {

                withdrop += money;
                System.out.println("客户" + Thread.currentThread().getName() + "余额" + withdrop);
            }

        }

    }

}

